package com.iwuyc.tools.commons.codec.type;

import com.iwuyc.tools.commons.codec.Codec;
import com.iwuyc.tools.commons.codec.TypeEnum;
import com.iwuyc.tools.commons.exception.IllegalFormatException;
import com.iwuyc.tools.commons.util.collection.ArrayUtil;

public class VoidCodec implements Codec<Void> {
    @Override
    public Void decode(byte[] data) {
        final int length = ArrayUtil.arrayLength(data);
        if (length != 1) {
            throw new IllegalFormatException("void的编码长度必须为1");
        }
        return null;
    }

    @Override
    public byte[] encode(Void data) {
        return new byte[]{TypeEnum.VOID.getFlags()};
    }

    @Override
    public TypeEnum[] supportedTypes() {
        return new TypeEnum[]{TypeEnum.VOID};
    }
}
